package cn.iocoder.an.module.business.dal.mysql.equipmentmanage;

import java.util.*;

import cn.iocoder.an.framework.common.pojo.PageResult;
import cn.iocoder.an.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.an.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.an.module.business.dal.dataobject.equipmentmanage.EquipmentManageDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.an.module.business.controller.admin.equipmentmanage.vo.*;
import org.springframework.stereotype.Repository;

/**
 * 设备台账 Mapper
 *
 * @author zzy
 */
@Mapper
public interface EquipmentManageMapper extends BaseMapperX<EquipmentManageDO> {

    default PageResult<EquipmentManageDO> selectPage(EquipmentManagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EquipmentManageDO>()
                .likeIfPresent(EquipmentManageDO::getEquipmentName, reqVO.getEquipmentName())
                .likeIfPresent(EquipmentManageDO::getDeptName, reqVO.getDeptName())
                .likeIfPresent(EquipmentManageDO::getCode, reqVO.getCode())
                .likeIfPresent(EquipmentManageDO::getInstallPosition, reqVO.getInstallPosition())
                .eqIfPresent(EquipmentManageDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(EquipmentManageDO::getEquipmentClassify, reqVO.getEquipmentClassify())
                .eqIfPresent(EquipmentManageDO::getEquipmentStatus, reqVO.getEquipmentStatus())
                .eqIfPresent(EquipmentManageDO::getEquipmentType, reqVO.getEquipmentType())
                .orderByDesc(EquipmentManageDO::getId));
    }

    default PageResult<EquipmentManageDO> selectCheckPage(EquipmentManagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EquipmentManageDO>()
                .likeIfPresent(EquipmentManageDO::getEquipmentName, reqVO.getEquipmentName())
                .likeIfPresent(EquipmentManageDO::getDeptName, reqVO.getDeptName())
                .likeIfPresent(EquipmentManageDO::getInstallPosition, reqVO.getInstallPosition())
                .eqIfPresent(EquipmentManageDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(EquipmentManageDO::getEquipmentClassify, reqVO.getEquipmentClassify())
                .eqIfPresent(EquipmentManageDO::getEquipmentStatus, reqVO.getEquipmentStatus())
                .eqIfPresent(EquipmentManageDO::getEquipmentType, reqVO.getEquipmentType())
                .last("ORDER BY CASE WHEN last_check_time IS NULL THEN 1 ELSE 0 END, last_check_time ASC"));
    }

}